package com.coda.controller;

import com.coda.common.PageResult;
import com.coda.common.Result;
import com.coda.dto.PageDto;
import com.coda.entity.Store;
import com.coda.service.StoreService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/warehouse/store")
public class StoreController {

    @Autowired
    private StoreService storeService;

    /**
     * 分页查询仓库列表
     */
    @GetMapping("/store-page-list")
    @ApiOperation("分页查询仓库列表")
    public Result getStorePage(PageDto pageDto, Store store){
        PageResult pageResult = storeService.getstorePage(pageDto,store);
        return Result.ok(pageResult);
    }
    /**
     * 修改仓库信息
     */
    @PutMapping("/store-update")
    @ApiOperation("修改仓信息")
    public Result storeUpdate(@RequestBody Store store){
        storeService.updateStore(store);
        return Result.ok("修改成功");
    }

    /**
     * 根据编号查询仓库
     */
    @GetMapping("/store-num-check")
    @ApiOperation("根据编号查询仓库")
    public Result getStore(Store store){
        Store store1 = storeService.getStore(store);
        return Result.ok(store1 == null);
    }

    /**
     * 添加仓库
     */
    @PostMapping("/store-add")
    @ApiOperation("添加仓库")
    public Result addStore(@RequestBody Store store){
        storeService.addStore(store);
        return Result.ok("添加成功");
    }

    /**
     * 删除仓库
     */
    @DeleteMapping("/store-delete/{id}")
    @ApiOperation("删除仓库")
    public Result deleteStore(@PathVariable Long id){
        storeService.deleteStre(id);
        return Result.ok("删除成功");
    }
}
